#include <vector>
using namespace std;

class Solution {
public:
    void sortColors(vector<int>& nums) {
        int n = nums.size();
        int left = -1 ,right = n , cur = 0;
        while(cur < right){
            if(nums[cur] == 0)  swap(nums[cur++],nums[++left]);
            else if(nums[cur] ==1) cur++;
            else if(nums[cur] == 2) swap(nums[cur],nums[--right]);
        }
    }
};